package com.hong.concurrent.chapter5;

/**
 * @Author csh
 * @Description
 * @Date 2018/6/30 20:21
 */
public class Gate {

    private int counter =0;
    private String name = "Nobody";
    private String address = "Nowhere";

    public synchronized void pass(String name,String address){
        this.counter++;
        this.name =name;
        this.address=address;
        verify();

    }

    private void  verify(){
        if(this.name.charAt(0)!=this.address.charAt(0)){
            System.out.println("*********BROKEN**********"+toString());
        }
    }

    public synchronized String toString(){
        return "No."+counter+":"+name+","+address;
    }


}
